import FitParser from "fit-file-parser"
import fs from "fs"

const filename = "2025-05-17.1747467303000"

fs.readFile(`./output/${filename}.fit`, function (err, content) {
  // Create a FitParser instance (options argument is optional)
  var fitParser = new FitParser.default({
    force: true,
    speedUnit: "km/h",
    lengthUnit: "km",
    temperatureUnit: "kelvin",
    pressureUnit: "bar", // accept bar, cbar and psi (default is bar)
    elapsedRecordField: true,
    mode: "cascade",
  })

  // Parse your file
  fitParser.parse(content, function (error, data) {
    // Handle result of parse method
    if (error) {
      console.log(error)
    } else {
      console.table(JSON.stringify(data))
      fs.writeFileSync(`./${filename}.json`, JSON.stringify(data))
    }
  })
})
